/*  
 * Copyright (C) 2011 Marta Spodymek
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *  
 */
package org.prometheuscode.web.feedback.domain;

/**
 * 
 * Implementation of {@link IFeedInput}
 * 
 * @author marta
 */
public class FeedInput implements IFeedInput {

    private int id;

    private String answer;

    /* this name is unique in a feed */
    private String name;

    private IFeed feed;

    public FeedInput() {
    }

    public FeedInput(int id, String answer, String name) {
	this.id = id;
	this.answer = answer;
	this.name = name;
    }

    @Override
    public int getId() {
	return this.id;
    }

    @Override
    public void setId(int id) {
	this.id = id;
    }

    @Override
    public String getAnswer() {
	return this.answer;
    }

    @Override
    public void setAnswer(String answer) {
	this.answer = answer;
    }

    @Override
    public void setName(String name) {
	this.name = name;

    }

    @Override
    public String getName() {
	return this.name;
    }

    /**
     * @return the feed
     */
    public IFeed getFeed() {
	return this.feed;
    }

    /**
     * @param feed
     *            the feed to set
     */
    public void setFeed(IFeed feed) {
	this.feed = feed;
    }

    @Override
    public boolean equals(Object obj) {
	if (obj == this) {
	    return true;
	}

	if (obj == null || !(IFeed.class.isAssignableFrom(obj.getClass()))) {
	    return false;
	}

	IFeedInput feedInput = (IFeedInput) obj;

	return ((this.name == feedInput.getName()) && this.feed.getId().equals(
		feedInput.getFeed().getId()));
    }

    @Override
    public final int hashCode() {
	return this.name.hashCode() + this.feed.getId().hashCode();

    }

}
